/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package by.bsuir.bbs.requesthelper;

import by.bsuir.bbs.commands.*;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Администратор
 */
public class RequestHelper {

    private static RequestHelper instance = new RequestHelper();
    HashMap<String, Command> commands = new HashMap<String, Command>();

    private RequestHelper() {
        commands.put("test", new Test());
        commands.put("register", new RegCommand());
    }

    public Command getCommand(HttpServletRequest request) {
        String action = request.getParameter("command");
        Command command = commands.get(action);
        if (command == null) {
            command = new NoCommand();
        }
        return command;
    }

    public static RequestHelper getInstance() {
        return instance;
    }
}